﻿using Ebusiness_OrderService.DomainEvent;
using Ebusiness_OrderService.DomainEvent.Dto;
using Ebusiness_OrderService.Model;
using Ebusiness_OrderService.Repositorys;
using Ebusiness_OrderService.Services.Dtos.Order;
using MediatR;
using Servicecomb.Saga.Omega.Abstractions.Transaction;
using Volo.Abp;
using Volo.Abp.Application.Services;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.EventBus;

namespace Ebusiness_OrderService.Services
{
    [Dependency(ServiceLifetime.Singleton)]
    [RemoteService(IsEnabled = false)]
    public class OrderService : CrudAppService<Order, OrderDto, Guid>, IOrderService
    {
        //两种事件
        //1、DDD中的事件分为两种类型:领域事件(DomainEvents)和集成事件(Integration Events）
        //2、领域事件:在同一个微服务内的聚合之间的事件传递。使用进程内的通信机制完成。
        //3、集成事件:跨微服务的事件传递。使用事件总线(EventBus) 实现。
        public IMediator mediator { get; set; }

        //消息发布者
        public IEventBus _eventBus { get; set; }

        public OrderService(IOrderRepository repository) : base(repository)
        {

        }

        public override async Task<OrderDto> CreateAsync(OrderDto input)
        {
            //领域事件:在同一个微服务内的聚合之间的事件传递。使用进程内的通信机制完成
            //添加商品成功之后给用户发送短信   发布事件
            //await mediator.Publish(new PostNotification() { Body = "xxxxxxx " });
            //消息生产者（发布者）
            //await _eventBus.PublishAsync(new OrderCreatedEto
            //{
            //    OrderId = Guid.NewGuid(),
            //    Price = 88.88m
            //});
            //var ti = this.GetHashCode();
            //var dd = Repository.GetDbContext().GetHashCode();
            return await base.CreateAsync(input);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public override Task DeleteAsync(Guid id)
        {
            return base.DeleteAsync(id);
        }

        public Task<string> Custome()
        {
            //throw new NotImplementedException();
            return Task.FromResult("1234");
        }
    }
}
